/**
 * JAVACC DEMO 1.0
 * @copy right iussoft company All rights reserved.
 */
package com.apache.passport.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apache.tools.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.apache.action.PlatFromAction;
import com.apache.api.manager.BaseManager;
import com.apache.api.vo.ResultMsg;
import com.apache.cache.util.Validator;
import com.apache.database.constant.SystemTools;
import com.apache.passport.common.PassPortConst;
import com.apache.passport.common.PassportHelper;
import com.apache.passport.entity.LoginInfo;
import com.apache.passport.entity.Token;
import com.apache.passport.manager.LoginInfoManager;

/**
 * description: 获取最后信息 
 * @author Hou Dayu 创建时间：2016-12-22
 * @Copyright(c)2014:
 */
@Controller
@RequestMapping({ "/passport/last/" })
public class LastMsgAction extends PlatFromAction<LoginInfo> {

    private String COOKIENAME = SystemTools.getInstance().getValue("cookieName");
    @Autowired
    private LoginInfoManager loginInfoManager;

    /**
     * description:  获取上次登录信息
     * @param request
     * @param response
     * @return
     * @author Hou Dayu 
     * @update 2014-12-22
     */
    @RequestMapping("lastmsg.action")
    @ResponseBody
    public Object lastmsg(HttpServletRequest request, HttpServletResponse response) {
        ResultMsg rmsg = new ResultMsg("F", "获取上次登录信息失败");
        String tokenCookie = StrUtil.doNull(PassportHelper.getInstance().getCurrCookie(request),request.getHeader("zuultokenid"));
        Token token = PassPortConst.getToken(tokenCookie);
        if (Validator.isEmpty(token)) {
            rmsg.setMsg("获取用户信息失败");
            return rmsg;
        }

        LoginInfo loginInfo = token.getLoginInfo();
        if (Validator.isEmpty(loginInfo)) {
            rmsg.setMsg("未查询到您有上次登录记录");
            return rmsg;
        }
        return loginInfo;
    }

    @Override
    protected BaseManager<LoginInfo> getBaseManager() {

        return null;
    }

    @Override
    protected String getPrefix() {

        return null;
    }

    @Override
    protected Object data(HttpServletRequest httpservletrequest, String s, String s1) {
        return null;
    }

}
